﻿using Macro_stone.PoModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.Service.SystemManager;

namespace SystemCenterSoa.ApiProject.Area.SystemManager
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentStaffController : SystemManagerBaseController
    {
        private DepartmentStaffService _DepartmentStaffService;
        public DepartmentStaffController(DepartmentStaffService DepartmentStaffService)
        {
            _DepartmentStaffService = DepartmentStaffService;
        }

        /// <summary>
        /// 部门—显示
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<List<DepartmentPo>> DepartmentPoInquire(int pageIndex, int pageSize, string deptName)
        {
            try
            {
                var data = _DepartmentStaffService.DepartmentPoInquire(pageIndex, pageSize, deptName);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DepartmentPo>>(ex);
            }
        }

        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel<bool> DepartmentPoAdd(DepartmentPo view)
        {
            try
            {

                var data = _DepartmentStaffService.DepartmentPoAdd(view);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        /// <summary>
        /// 部门反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<DepartmentPo> DepartmentPoOne(int id)
        {
            try
            {
                var data = _DepartmentStaffService.DepartmentPoOne(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<DepartmentPo>(ex);
            }
        }

        /// <summary>
        /// 部门修改
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel<bool> DepartmentPoUpdate(DepartmentPo view)
        {
            try
            {
                var data = _DepartmentStaffService.DepartmentPoUpdate(view);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        /// <summary>
        /// 部门删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<bool> DepartmentPoDelete(int id)
        {
            try
            {
                var data = _DepartmentStaffService.DepartmentPoDelete(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        /// <summary>
        /// 人员管理—显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="buming"></param>
        /// <param name="name"></param>
        /// <param name="zhuang"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<List<StaffDto>> staffPoIndex(int pageIndex, int pageSize, string buming, string name, int? zhuang)
        {
            try
            {
                var data = _DepartmentStaffService.staffPoIndex(pageIndex, pageSize, buming, name, zhuang);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<StaffDto>>(ex);
            }
        }

        /// <summary>
        /// 人员管理—添加
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel<bool> StaffPoAdd(StaffPo view)
        {
            try
            {
                var data = _DepartmentStaffService.StaffPoAdd(view);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        /// <summary>
        /// 人员管理—删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<bool> StaffPoDelete(int id)
        {
            try
            {
                var data = _DepartmentStaffService.StaffPoDelete(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        /// <summary>
        /// 部门下拉【多的不用在意，只用ID和名字就可】
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultModel<List<DepartmentPo>> departmentPoXia()
        {
            try
            {
                var data = _DepartmentStaffService.departmentPoXia();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DepartmentPo>>(ex);
            }
        }

    }
}
